package com.tingyuge.base.structrue.quene;

/**
 * @Created by xiaodao
 */
public class ArrayQueue<E> implements Queue<E> {

    Array<E> array;
    public ArrayQueue() {
        array = new Array<>();
    }

    public ArrayQueue(int capacity){
        array = new Array<>(capacity);
    }

    @Override
    public int getSize() {
        return array.getSize();
    }

    @Override
    public boolean isEmpty() {
        return array.isEmpty();
    }

    @Override
    public void enQueue(E e ) {
        array.addLast(e);
    }

    @Override
    public E deQueue() {
        return array.removeFirst();
    }

    @Override
    public E getFront() {
        return array.getFirst();
    }


    public int getCapacity(){
        return array.getCapacity();
    }

    @Override
    public String toString() {
        StringBuilder builder =new StringBuilder();
        builder.append("Queue: ");
        builder.append("front [");
        for (int i = 0; i < array.getSize(); i++) {
            builder.append(array.get(i));
            if(i != (array.getSize()-1))
                builder.append(", ");

        }
        builder.append("] tail ");
        return builder.toString();
    }
}
